***Replication Code for "Do Immigrants' Partisan Preferences Influence Americans' Support for Immigration?"


**Construction of Variables
*create variable measuring immigration attitudes
gen immpref = max(Q15Ar1, Q15Br1, Q15Cr1, Q15Dr1)

*create manipulation-check variable (1=believe immigrants support Trump, 0=believe do not support Trump)
gen immmanip = Q15E_New-1

*create dummy variable for immigration treatment (1=treatment; 0=control)
gen immtreat = 1 if hQ15Ver==2
replace immtreat = 1 if hQ15Ver==4
replace immtreat = 0 if hQ15Ver==1
replace immtreat = 0 if hQ15Ver==3

*create dummy variable for immigrant country of origin (1=Vietnam; 0 = Venezuela)
gen viettreat = 1 if hQ15Ver==3
replace viettreat = 1 if hQ15Ver==4
replace viettreat = 0 if hQ15Ver==1
replace viettreat = 0 if hQ15Ver==2

gen ven_group=. 
replace ven_group=1 if viettreat==0
replace ven_group=0 if viettreat==1

*construct measures of party ID
gen id_dem = 0
replace id_dem = 1 if Q27==2
replace id_dem = 1 if Q28C==2

gen id_rep = 0
replace id_rep = 1 if Q27==1
replace id_rep = 1 if Q28C==1

gen tripartyid = .
replace trip = 1 if partyid<3
replace trip = 2 if partyid == 3
replace trip = 3 if partyid >3

*construct variables for vote intention (dummies indicating whether respondent intends to vote for Trump and Dems, respectively)
gen trumpvote = 1 if Q29==2
replace trumpvote = 0 if Q29!=2

gen demvote = 1 if Q29==1
replace demvote = 0 if Q29!=1


*construct ordinal scale for party ID (Strong Dem=1, Weak Dem=2, Ind=3,Weak Rep=4, Strong Rep=5)
gen partyid = 1 if Q28B==1
replace partyid = 2 if Q28B==2
replace partyid = 2 if Q28C==2 
replace partyid = 3 if Q28C==3
replace partyid = 4 if Q28A==2
replace partyid = 4 if Q28C==1 
replace partyid = 5 if Q28A==1


*construct interaction variables
gen immtreatXviettreat = immtreat*viettreat
gen immtreatXid_ind = immtreat*id_ind
gen immtreatXid_dem = immtreat*id_dem
gen immtreatXid_rep = immtreat*id_rep
gen immtreatXpartyid1 = 1 if immtreat==1 & partyid==1
replace immtreatXpartyid1 = 0 if immtreat==0
replace immtreatXpartyid1 = 0 if partyid!=1
gen immtreatXpartyid2 = 1 if immtreat==1 & partyid==2
replace immtreatXpartyid2 = 0 if immtreat==0
replace immtreatXpartyid2 = 0 if partyid!=2
gen immtreatXpartyid3 = 1 if immtreat==1 & partyid==3
replace immtreatXpartyid3 = 0 if immtreat==0
replace immtreatXpartyid3 = 0 if partyid!=3
gen immtreatXpartyid4 = 1 if immtreat==1 & partyid==4
replace immtreatXpartyid4 = 0 if immtreat==0
replace immtreatXpartyid4 = 0 if partyid!=4
gen immtreatXpartyid5 = 1 if immtreat==1 & partyid==5
replace immtreatXpartyid5 = 0 if immtreat==0
replace immtreatXpartyid5 = 0 if partyid!=5


*create alternative names for immigration treatment variable (which we use to generate conditional treatment effect plots)
gen immtreat1 = immtreat
gen immtreat2 = immtreat
gen immtreat3 = immtreat
gen immtreat4 = immtreat
gen immtreat5 = immtreat


*construct and/or reorder attitudinal variables
gen white = Q2
replace white = 0 if Q2!=1

gen nationalism_r = 6+nationalism*-1
gen ethnocentrist_r = 6+ethnocentrist*-1
gen internationalism_r = 6+internationalism*-1
gen generaltrust_r = 6+generaltrust*-1

gen left = 1 if ideology<5
replace left = 0 if ideology>4
gen right = 1 if ideology>5
replace right = 0 if ideology<6

*rescale control variables so that median = 0
gen income0 = income-3
gen education0 = education-4
gen dummy_QAGE20 = dummy_QAGE2-3
gen ethnocentrist_r0 = ethnocentrist_r-2
gen nationalism_r0 = nationalism_r-5
gen internationalism_r0 = internationalism_r-4
gen generaltrust_r0 = generaltrust_r-3


**Figure 1 - note: need to adjust labels and colors  
reg immpref triparty##i.immtreat
margins, at(triparty=(1(1)3) immtreat=(0 1)) vsquish

marginsplot, recast(bar) addplot((margins, at(triparty=(1(1)3) immtreat=0)  (margins, at(triparty=(1(1)3) immtreat=1)))) title ("") xtitle("Party ID") ytitle("Support for Immigration") legend(order(1 "Control=0" 2 "Trump treatment=1") position(0) bplacement(n)) yscale(r(0 6)) ylabel (0 1 2 3 4 5 6) plotopts(barw(.4)) 


**Figure 2 - note: need to adjust labels
*estimate treatment effect for Democrats
reg immpref immtreat id_ind id_rep immtreatXid_ind immtreatXid_rep income education female dummy_QAGE2 white
estimates store immdem

*estimate treatment effect for Independents
reg immpref immtreat2 id_rep id_dem immtreatXid_rep immtreatXid_dem income education female dummy_QAGE2 white
estimates store immind

*estimate treatment effect for Republicans
reg immpref immtreat3 id_ind id_dem immtreatXid_ind immtreatXid_dem income education female dummy_QAGE2 white
estimates store immrep

*plot treatment effects
coefplot immdem immind immrep, keep(immtreat immtreat2 immtreat3) xline(0, lcolor(gray)) name(immplot, replace) ciopts(lcolor(black)) mcolor(black)



**Figure 3 - note: need to adjust labels for immtreat1 immreat2 immtreat3
*estimate treatment effect for Strong Dems
reg immpref immtreat1 immtreatXpartyid2 immtreatXpartyid3 immtreatXpartyid4 immtreatXpartyid5 i.partyid income education female dummy_QAGE2 white
estimates store immcat1

*estimate treatment effect for Weak Dems
reg immpref immtreat2 immtreatXpartyid1 immtreatXpartyid3 immtreatXpartyid4 immtreatXpartyid5 i.partyid income education female dummy_QAGE2 white
estimates store immcat2

*estimate treatment effect for Independents
reg immpref immtreat3 immtreatXpartyid1 immtreatXpartyid2 immtreatXpartyid4 immtreatXpartyid5 i.partyid income education female dummy_QAGE2 white
estimates store immcat3

*estimate treatment effect for Weak Republicans
reg immpref immtreat4 immtreatXpartyid1 immtreatXpartyid2 immtreatXpartyid3 immtreatXpartyid5 i.partyid income education female dummy_QAGE2 white
estimates store immcat4

*estimate treatment effect for Strong Republicans
reg immpref immtreat5 immtreatXpartyid1 immtreatXpartyid2 immtreatXpartyid3 immtreatXpartyid4 i.partyid income education female dummy_QAGE2 white
estimates store immcat5

*plot treatment effects
coefplot immcat1 immcat2 immcat3 immcat4 immcat5, keep(immtreat1 immtreat2 immtreat3 immtreat4 immtreat5) xline(0, lcolor(gray)) name(immcatplot, replace) ciopts(lcolor(black)) mcolor(black)



**Table A1
tab dummy_Q3
tab dummy_QAGE2
tab female
tab usregion


**Figure B1 - note: adjust labels
reg immmanip immtreat
margins, at(immtreat=(0(1)1))
marginsplot, recast(bar) yscale(range(0 .7)) ylabel(0 .1 .2 .3 .4 .5 .6 .7) plotopts(barw(.4)) xsize(2.75)


**Figure B2 - note: adjust labels, colors
reg immmanip immtreat##ven_group
margins, at(immtreat=(0(1)1) ven_group=(0 1)) vsquish
marginsplot, recast(bar) addplot((margins, at(immtreat=(0(1)1) ven_group=0)  (margins, at(immtreat=(0(1)1) ven_group=1)))) title ("") xtitle("") ytitle("Proportion of Respondents") legend(order(1 "Vietnam" 2 "Venezuela") position(0) bplacement(n)) yscale(r(0 .8)) ylabel (0 .1 .2 .3 .4 .5 .6 .7 .8) plotopts(barw(.4)) 

**Figure C1
*histogram for Democrats
twoway (histogram immpref if id_dem==1 & immtreat==0, discrete color(black%30)) (histogram immpref if id_dem==1 & immtreat==1, discrete color(gray%30)), name(histdem, replace)

*histogram for Independents
twoway (histogram immpref if id_ind==1 & immtreat==0, discrete color(black%30)) (histogram immpref if id_ind==1 & immtreat==1, discrete color(gray%30)), name(histind, replace)

*histogram for Republicans
twoway (histogram immpref if id_rep==1 & immtreat==0, discrete color(black%30)) (histogram immpref if id_rep==1 & immtreat==1, discrete color(gray%30)), name(histrep, replace)

*Plot histograms together
graph combine histdem histind histrep, col(3) ycommon



**Table C1
*model 1 (no controls)
reg immpref immtreat##id_dem immtreat##id_rep 

*model 2 (demographic controls)
reg immpref immtreat##id_dem immtreat##id_rep  income education female dummy_QAGE2 white

*model 3 (all controls)
reg immpref immtreat##id_dem immtreat##id_rep  income education female dummy_QAGE2 white ethnocentrist_r nationalism_r internationalism_r generaltrust_r

*model 4 (no controls, interact with Democrat dummy only)
reg immpref immtreat##id_dem 

*model 5 (demographic controls, interact with Democrat dummy only)
reg immpref immtreat##id_dem  income education female dummy_QAGE2 white

*model 6 (all controls, interact with Democrat dummy only)
reg immpref immtreat##id_dem income education female dummy_QAGE2 white ethnocentrist_r nationalism_r internationalism_r generaltrust_r


**Figure C2 - note: adjust labels
*treatment effect for Democrats
reg immpref immtreat id_ind id_rep immtreatXid_ind immtreatXid_rep immtreat##c.income0 immtreat##c.education0 immtreat##c.female immtreat##c.dummy_QAGE20 immtreat##c.white
estimates store immcat1c

*treatment effect for Independents
reg immpref immtreat2 id_dem id_rep immtreatXid_dem immtreatXid_rep immtreat##c.income0 immtreat##c.education0 immtreat##c.female immtreat##c.dummy_QAGE20 immtreat##c.white
estimates store immcat2c

*treatment effect for Republicans
reg immpref immtreat3 id_ind id_dem immtreatXid_ind immtreatXid_dem immtreat##c.income0 immtreat##c.education0 immtreat##c.female immtreat##c.dummy_QAGE20 immtreat##c.white
estimates store immcat3c

*combine three plots
coefplot immcat1c immcat2c immcat3c, keep(immtreat immtreat2 immtreat3) xline(0, lcolor(gray)) name(immcatplot_interactioncontrols, replace) ciopts(lcolor(black)) mcolor(black)


**Figure C3 - note: adjust labels
*treatment effect for Democrats
reg immpref immtreat id_ind id_rep immtreatXid_ind immtreatXid_rep immtreat##c.income0 immtreat##c.education0 immtreat##c.female immtreat##c.dummy_QAGE20 immtreat##c.white immtreat##c.ethnocentrist_r0 immtreat##c.nationalism_r0 immtreat##c.internationalism_r0 immtreat##c.generaltrust_r0
estimates store immcat1c_a

*treatment effect for Independents
reg immpref immtreat2 id_dem id_rep immtreatXid_dem immtreatXid_rep immtreat##c.income0 immtreat##c.education0 immtreat##c.female immtreat##c.dummy_QAGE20 immtreat##c.white immtreat##c.ethnocentrist_r0 immtreat##c.nationalism_r0 immtreat##c.internationalism_r0 immtreat##c.generaltrust_r0
estimates store immcat2c_a

*treatment effect for Republicans
reg immpref immtreat3 id_ind id_dem immtreatXid_ind immtreatXid_dem immtreat##c.income0 immtreat##c.education0 immtreat##c.female immtreat##c.dummy_QAGE20 immtreat##c.white immtreat##c.ethnocentrist_r0 immtreat##c.nationalism_r0 immtreat##c.internationalism_r0 immtreat##c.generaltrust_r0
estimates store immcat3c_a

*combine three plots
coefplot immcat1c_a immcat2c_a immcat3c_a, keep(immtreat immtreat2 immtreat3) xline(0, lcolor(gray)) name(immcatplot_interactions_all, replace) ciopts(lcolor(black)) mcolor(black)


**Table C2
svyset _n [pweight=dem_weights], vce(linearized) singleunit(missing)
svy: reg immpref immtreat##id_dem immtreat##id_rep
svy: reg immpref immtreat##id_dem immtreat##id_rep  income education female dummy_QAGE2 white
svy: reg immpref immtreat##id_dem immtreat##id_rep  income education female dummy_QAGE2 white ethnocentrist_r nationalism_r internationalism_r generaltrust_r


**Table C3
*five point party ID scale as moderator
reg immpref immtreat##i.partyid  income education female dummy_QAGE2 white

*voting intentions as moderator
reg immpref immtreat##demvote immtreat##trumpvote  income education female dummy_QAGE2 white


**Figure D1 - note: adjust labels
*heterogeneity by immigrant country of origin 
reg immpref immtreat1 id_ind id_rep immtreatXid_ind immtreatXid_rep  income education female dummy_QAGE2 white if viettreat==0
estimates store imm1ven
reg immpref immtreat2 id_dem id_rep immtreatXid_dem immtreatXid_rep income education female dummy_QAGE2 white if viettreat==0
estimates store imm2ven
reg immpref immtreat3 id_ind id_dem immtreatXid_ind immtreatXid_dem income education female dummy_QAGE2 white if viettreat==0
estimates store imm3ven
reg immpref immtreat1 id_ind id_rep immtreatXid_ind immtreatXid_rep  income education female dummy_QAGE2 white if viettreat==1
estimates store imm1viet
reg immpref immtreat2 id_dem id_rep immtreatXid_dem immtreatXid_rep income education female dummy_QAGE2 white if viettreat==1
estimates store imm2viet
reg immpref immtreat3 id_ind id_dem immtreatXid_ind immtreatXid_dem income education female dummy_QAGE2 white if viettreat==1
estimates store imm3viet
coefplot imm1ven imm2ven imm3ven imm1viet imm2viet imm3viet, keep(immtreat1 immtreat2 immtreat3) xline(0, lcolor(gray)) name(immplot_country, replace) ciopts(lcolor(black)) mcolor(black)

*heterogeneity by respondent ethnicity
reg immpref immtreat1 id_ind id_rep immtreatXid_ind immtreatXid_rep income education female dummy_QAGE2  if white==0
estimates store imm1nw
reg immpref immtreat2 id_dem id_rep immtreatXid_dem immtreatXid_rep income education female dummy_QAGE2  if white==0
estimates store imm2nw
reg immpref immtreat3 id_ind id_dem immtreatXid_ind immtreatXid_dem income education female dummy_QAGE2  if white==0
estimates store imm3nw
reg immpref immtreat1 id_ind id_rep immtreatXid_ind immtreatXid_rep income education female dummy_QAGE2  if white==1
estimates store imm1w
reg immpref immtreat2 id_dem id_rep immtreatXid_dem immtreatXid_rep income education female dummy_QAGE2  if white==1
estimates store imm2w
reg immpref immtreat3 id_ind id_dem immtreatXid_ind immtreatXid_dem income education female dummy_QAGE2  if white==1
estimates store imm3w
coefplot imm1w imm2w imm3w imm1nw imm2nw imm3nw, keep(immtreat1 immtreat2 immtreat3) xline(0, lcolor(gray)) name(immplot_ethnic, replace) ciopts(lcolor(black)) mcolor(black)

*heterogeneity by respondent gender
reg immpref immtreat1 id_ind id_rep immtreatXid_ind immtreatXid_rep income education white dummy_QAGE2  if female==0
estimates store imm1m
reg immpref immtreat2 id_dem id_rep immtreatXid_dem immtreatXid_rep income education white dummy_QAGE2  if female==0
estimates store imm2m
reg immpref immtreat3 id_ind id_dem immtreatXid_ind immtreatXid_dem income education white dummy_QAGE2  if female==0
estimates store imm3m
reg immpref immtreat1 id_ind id_rep immtreatXid_ind immtreatXid_rep income education white dummy_QAGE2  if female==1
estimates store imm1f
reg immpref immtreat2 id_dem id_rep immtreatXid_dem immtreatXid_rep income education white dummy_QAGE2  if female==1
estimates store imm2f
reg immpref immtreat3 id_ind id_dem immtreatXid_ind immtreatXid_dem income education white dummy_QAGE2  if female==1
estimates store imm3f
coefplot imm1m imm2m imm3m imm1f imm2f imm3f, keep(immtreat1 immtreat2 immtreat3) xline(0, lcolor(gray)) name(immplot_gender, replace) ciopts(lcolor(black)) mcolor(black)

*heterogeneity by respondent age
reg immpref immtreat1 id_ind id_rep immtreatXid_ind immtreatXid_rep income education female  white if dummy_QAGE2<3
estimates store imm1y
reg immpref immtreat2 id_dem id_rep immtreatXid_dem immtreatXid_rep income education female  white if dummy_QAGE2<3
estimates store imm2y
reg immpref immtreat3 id_ind id_dem immtreatXid_ind immtreatXid_dem income education female  white if dummy_QAGE2<3
estimates store imm3y
reg immpref immtreat1 id_ind id_rep immtreatXid_ind immtreatXid_rep income education female  white if dummy_QAGE2>2
estimates store imm1o
reg immpref immtreat2 id_dem id_rep immtreatXid_dem immtreatXid_rep income education female  white if dummy_QAGE2>2
estimates store imm2o
reg immpref immtreat3 id_ind id_dem immtreatXid_ind immtreatXid_dem income education female  white if dummy_QAGE2>2
estimates store imm3o
coefplot imm1y imm2y imm3y  imm1o imm2o imm3o, keep(immtreat1 immtreat2 immtreat3) xline(0, lcolor(gray)) name(immplot_age, replace) ciopts(lcolor(black)) mcolor(black)

*heterogeneity by respondent income
reg immpref immtreat1 id_ind id_rep immtreatXid_ind immtreatXid_rep  education female dummy_QAGE2 white if income<4
estimates store imm1p
reg immpref immtreat2 id_dem id_rep immtreatXid_dem immtreatXid_rep education female dummy_QAGE2 white if income<4
estimates store imm2p
reg immpref immtreat3 id_ind id_dem immtreatXid_ind immtreatXid_dem  education female dummy_QAGE2 white if income<4
estimates store imm3p
reg immpref immtreat1 id_ind id_rep immtreatXid_ind immtreatXid_rep education female dummy_QAGE2 white if income>3
estimates store imm1r
reg immpref immtreat2 id_dem id_rep immtreatXid_dem immtreatXid_rep  education female dummy_QAGE2 white if income>3
estimates store imm2r
reg immpref immtreat3 id_ind id_dem immtreatXid_ind immtreatXid_dem  education female dummy_QAGE2 white if income>3
estimates store imm3r
coefplot imm1p imm2p imm3p imm1r imm2r imm3r, keep(immtreat1 immtreat2 immtreat3) xline(0, lcolor(gray)) name(immplot_inc, replace) ciopts(lcolor(black)) mcolor(black)

*heterogeneity by respondent education
reg immpref immtreat1 id_ind id_rep immtreatXid_ind immtreatXid_rep income  female dummy_QAGE2 white if education<5
estimates store imm1le
reg immpref immtreat2 id_dem id_rep immtreatXid_dem immtreatXid_rep income  female dummy_QAGE2 white if education<5
estimates store imm2le
reg immpref immtreat3 id_ind id_dem immtreatXid_ind immtreatXid_dem income  female dummy_QAGE2 white if education<5
estimates store imm3le
reg immpref immtreat1 id_ind id_rep immtreatXid_ind immtreatXid_rep income  female dummy_QAGE2 white if education>4
estimates store imm1he
reg immpref immtreat2 id_dem id_rep immtreatXid_dem immtreatXid_rep income  female dummy_QAGE2 white if education>4
estimates store imm2he
reg immpref immtreat3 id_ind id_dem immtreatXid_ind immtreatXid_dem income  female dummy_QAGE2 white if education>4
estimates store imm3he
coefplot imm1le imm2le imm3le imm1he imm2he imm3he, keep(immtreat1 immtreat2 immtreat3) xline(0, lcolor(gray)) name(immplot_educ, replace) ciopts(lcolor(black)) mcolor(black)

*combine six plots
graph combine immplot_country immplot_inc immplot_educ immplot_gender immplot_age  immplot_ethnic, xcommon col(2)



**Table D1
reg immpref immtreat viettreat  income education female dummy_QAGE2 white if id_dem==1
reg immpref immtreat viettreat  income education female dummy_QAGE2 white if id_ind==1
reg immpref immtreat viettreat  income education female dummy_QAGE2 white if id_rep==1
reg immpref immtreat viettreat immtreatXviettreat income education female dummy_QAGE2 white if id_dem==1
reg immpref immtreat viettreat immtreatXviettreat income education female dummy_QAGE2 white if id_ind==1
reg immpref immtreat viettreat immtreatXviettreat income education female dummy_QAGE2 white if id_rep==1


**Table E1
reg immpref immtreat##id_dem immtreat##id_rep  
reg immpref immtreat##c.partyid
reg immpref immtreat##c.ideology
reg immpref immtreat##left immtreat##right


**Table E2
reg immpref immtreat##id_ind immtreat##id_rep if left==1
reg immpref immtreat##id_ind immtreat##id_rep if left==0 & right==0
reg immpref immtreat##id_ind immtreat##id_rep if right==1

